package com;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;

/**
 * Created by apple on 17/2/8.
 */
public class Demo {

    public static void main(String[] args) {

        ExecutorService executor = Executors.newFixedThreadPool(4);


        Long l = System.currentTimeMillis();

        List<Future<Map>> list = new ArrayList();
        for (int i = 0; i < 100; i++) {
            Future<Map> future1 = executor.submit(new Callable<Map>() {
                @Override
                public Map call() throws Exception {
                    // TODO Auto-generated method stub
                    Map m = new HashMap();
                    for (int j = 0; j < 1000000; j++) {
                        if (5500 > j || 4500 > j || 3500 > j || 2500 > j || 1500 > j || 500 > j) {
                            m.put(j, j);
                        }
                    }
                    return m;
                }
            });
            list.add(future1);
        }

        try {
            for (int i = 0; i < 100; i++) {
                list.get(i).get().size();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

        executor.shutdown();

        System.out.println(System.currentTimeMillis() - l);

    }
}
